<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <title>登录</title>

    <link href="../css/loading.css" rel="stylesheet" type="text/css"/>


    <script type="text/javascript" charset="utf-8" src="../js/base/jquery.js"></script>
    <script type="text/javascript" charset="utf-8" src="../js/base/base.js"></script>
    <script type="text/javascript" charset="utf-8" src="../js/base/layer.js"></script>
    <script type="text/javascript" charset="utf-8" src="../js/base/md5.js"></script>

    <link href="../image/base/favicon.ico" mce_href="../image/base/favicon.ico" type="image/x-icon" rel="bookmark"/>
    <link href="../image/base/favicon.ico" mce_href="../image/base/favicon.ico" type="image/x-icon" rel="icon"/>
    <link href="../image/base/favicon.ico" mce_href="../image/base/favicon.ico" type="image/x-icon"
          rel="shortcut icon"/>

</head>
<body>

    <div id="header">
        <a href="../index.html" class="spark" target='_blank'></a>
    </div>
    <div class="main-login">
        <div class="register">
            <a href="register.html">还没账号？点此注册</a>
        </div>
        <div class="login">
            <div class="container">
                <h2>登录</h2>
                <h3>此账号可在网站内使用</h3>
                <div class="login-box">
                    <dl>
                        <dd>
                            <input id="phoneNumber" maxlength="11"  onkeyup="this.value=this.value.replace(/\D/g,'')"
                                   onafterpaste="this.value=this.value.replace(/\D/g,'')"  placeholder="请输入手机号"/>
                        </dd>
                        <div class="wrong-phone"></div>
                        <dd>
                            <input type="password" id="password" placeholder="请输入6-16位密码"/>
                        </dd>
                        <div class="wrong-pw"></div>
                        <dd><a class="login-button">登 录</a></dd>
                        <dd class="forget"><a href="forget.html">忘记密码？</a></dd>
                    </dl>

                </div>
            </div>
        </div>
    </div>
    <div id="footer">
        &copy;2015-2016  Motortravel  All Rights Reserved  浙ICP备16035685号
    </div>

</body>

<script>
    window.onload=function(){

        $('.login-button').click(function(){
            var tel_info = $('#phoneNumber').val();
            var psd_info = $('#password').val();
            var tel_preg = /^1[34578]\d{9}$/;
            var psd_preg=/^[a-zA-Z0-9_-]{6,16}$/;

            if (tel_info == '') {
                layer.msg('请填写您的手机号');
            } else if (!(tel_preg.test(tel_info))) {
                layer.msg('您的手机号填写有误');
            }else if (psd_info=='') {
                layer.msg('请填写您的密码');
            }else if (!(psd_preg.test(psd_info))) {
                layer.msg('您的密码格式填写有误');
            }else{
//                //md5加密
//                psd_info = hex_md5(psd_info);
//                $.get(url_link+'users/login',{
//                    mobile:tel_info,
//                    password:psd_info
//                },function(data){
//                    var obj=JSON.parse(data);
//                    if(obj.code==0){
//                        storage_user_id = obj.data.user_id;
//                        storage_is_admin = obj.data.is_admin;
//                        storage.setItem("_storage_user_id", storage_user_id);
//                        storage.setItem("_storage_is_admin", storage_is_admin);
//                        window.location.href="../index.html";
//                    }else{
//                        layer.msg(data.msg);
//                    }
//                });

                //md5未加密
                $.get(url_link+'users',{
                    mobile:tel_info,
                    password:psd_info
                },function(data){
                    try{
                        var obj=JSON.parse(data);
                        if(obj.code==0){
                            storage_user_id = obj.data.user_id;
                            storage_is_admin = obj.data.is_admin;
                            storage.setItem("_storage_user_id", storage_user_id);
                            storage.setItem("_storage_is_admin", storage_is_admin);
                            window.location.href="../index.html";
                        }else{
                            layer.msg(obj.msg);
                        }
                    }catch(e){
                        layer.msg(data.msg);
                    }

                });
            }
        });
    }
</script>


</html>
